﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace blackhouse.WebNemo.Business.Groups {
	public class GroupColumnCollection:IEnumerable<GroupColumn> {

		#region Fields

		private Dictionary<string, GroupColumn> namedColumns = new Dictionary<string, GroupColumn>();
		private Dictionary<int, GroupColumn> signedColumns = new Dictionary<int, GroupColumn>();

		#endregion

		#region Constructors

		#endregion

		#region Properties

		public GroupColumn this[string name] {
			get {
				if (this.namedColumns.ContainsKey(name))
					return this.namedColumns[name];
				else
					return null;
			}
		}

		public GroupColumn this[int columnId] {
			get {
				if (this.signedColumns.ContainsKey(columnId))
					return this.signedColumns[columnId];
				else
					return null;
			}
		}

		public int Count {
			get { return this.namedColumns.Count; }
		}

		#endregion

		#region Methods

		public void Clear() {
			this.namedColumns.Clear();
			this.signedColumns.Clear();
		}

		public void Add(GroupColumn column) {
			if (column != null && !this.namedColumns.ContainsKey(column.ColumnName)) {
				this.namedColumns.Add(column.ColumnName, column);
				this.signedColumns.Add(column.ColumnId, column);
			}
		}

		public IEnumerator<GroupColumn> GetEnumerator() {
			return this.namedColumns.Values.OrderBy(c=>c.ColumnSort).ThenBy(c=>c.ColumnName).GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
			return this.namedColumns.Values.OrderBy(c => c.ColumnSort).ThenBy(c => c.ColumnName).GetEnumerator();
		}

		#endregion

	}
}
